package org.linlinjava.litemall.db.service;

import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallWxExpressMapper;
import org.linlinjava.litemall.db.domain.*;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@Service
public class LitemallWxExpressService {
    @Resource
    private LitemallWxExpressMapper wxExpressMapper;

    /**
     * 获取全部签约公司(bizId部位)
     *
     * @return
     */
    public List<LitemallWxExpress> queryList() {
        LitemallWxExpressExample example = new LitemallWxExpressExample();
        example.or().andDeletedEqualTo(false);
        return wxExpressMapper.selectByExampleSelective(example);
    }

    public LitemallWxExpress queryByDeliveryId(String deliveryId) {
        LitemallWxExpressExample example = new LitemallWxExpressExample();
        example.or().andDeliveryIdEqualTo(deliveryId).andDeletedEqualTo(false);
        return wxExpressMapper.selectOneByExample(example);
    }

    public int updateById(LitemallWxExpress wxExpress) {
        wxExpress.setUpdateTime(LocalDateTime.now());
        return wxExpressMapper.updateByPrimaryKeySelective(wxExpress);
    }

    public void add(LitemallWxExpress wxExpress) {
        wxExpress.setAddTime(LocalDateTime.now());
        wxExpress.setUpdateTime(LocalDateTime.now());
        wxExpressMapper.insertSelective(wxExpress);

    }

    public void deleteById(Integer id) {
        wxExpressMapper.deleteByPrimaryKey(id);
    }

    public List<LitemallWxExpress> querySelective(String name, Integer page, Integer limit, String sort, String order) {
        LitemallWxExpressExample example = new LitemallWxExpressExample();
        LitemallWxExpressExample.Criteria criteria = example.createCriteria();

        if (!StringUtils.isEmpty(name)) {
            criteria.andNameLike("%" + name + "%");
        }

        criteria.andDeletedEqualTo(false);

        PageHelper.startPage(page, limit);
        return wxExpressMapper.selectByExample(example);
    }


}
